import request from '@/utils/request';

/**
 * 查询字典
 */
export const getDictType = (type: string) => {
  return request({
    url: `/system/dict/data/type/${type}`,
    method: 'get',
  });
};

/**
 * 访问统计今日在线
 */

export const getTodayOnlineCount = () => {
  return request({
    url: '/visitMonitor/statistics/online',
    method: 'get',
  });
};

/**
 * 访问统计报表
 * @param type {String} 1.近7天 2.近一个月 3.近一年
 */

export const getVisitReport = (type: string) => {
  return request({
    url: `visitMonitor/statistics/report/${type}`,
    method: 'get',
  });
};

/**
 * 限制统计报表
 * @param type {String} 1.今日 2.本周 3.本月 4.本年
 */
export const getLimitReport = (type: string) => {
  return request({
    url: `/visitMonitor/statistics/restrict/${type}`,
    method: 'get',
  });
};

/**
 * 服务器各项基本指标
 */

export const getServerBaseInfo = () => {
  return request({
    url: '/visitMonitor/statistics/serverTarget',
    method: 'get',
  });
};

/***********************************在线用户***********************************/
/**
 * 查询在线用户列表
 */
export function list(query: any) {
  return request({
    url: '/monitor/online/list',
    method: 'get',
    params: query,
  });
}

/**
 * 强退用户
 */
export function forceLogout(tokenId: any) {
  return request({
    url: '/monitor/online/' + tokenId,
    method: 'delete',
  });
}
/***********************************服务监控***********************************/
/**
 * 获取服务信息
 */
export function getServer() {
  return request({
    url: '/monitor/server',
    method: 'get',
  });
}
/***********************************缓存监控***********************************/
/**
 * 查询缓存详细
 */
export function getCache() {
  return request({
    url: '/monitor/cache',
    method: 'get',
  });
}
/***********************************黑名单***********************************/
/**
 * 查询ip列表
 */
export function BlacklistTable(query: any) {
  return request({
    url: '/visitBlack/list',
    method: 'get',
    params: query,
  });
}

/**
 * 删除
 */
export function delBlackIplist(ids: any) {
  return request({
    url: `/visitBlack/deleteBatch/${ids}`,
    method: 'delete',
  });
}

/**
 * 通过id 获取数据渲染 弹框
 */
export function EditIdGetData(id: any) {
  return request({
    url: `visitBlack/queryById/${id}`,
    method: 'get',
  });
}

/**
 * 新增 的确认
 */
export function AddBlack(data: any) {
  return request({
    url: '/visitBlack/add',
    method: 'post',
    data,
  });
}

/**
 * 编辑 的确认
 */
export function EditBlackIp(data: any) {
  return request({
    url: '/visitBlack/edit',
    method: 'put',
    data,
  });
}

/**
 * 导入
 */
export function ImportBlack(data: any) {
  return request({
    url: '/visitBlack/import',
    method: 'post',
    data,
  });
}

/**
 * 导出
 */
export const ExportBlack = (ids: any) => {
  return request({
    url: `/visitBlack/export?ids=${ids}`,
    method: 'post',
    responseType: 'blob',
  });
};

/***********************************白名单***********************************/
/**
 * 查询ip列表
 */
export function WhitelistTable(query: any) {
  return request({
    url: '/visitWhite/list',
    method: 'get',
    params: query,
  });
}

/**
 * 删除
 */
export function delWhiteIplist(ids: any) {
  return request({
    url: `/visitWhite/deleteBatch/${ids}`,
    method: 'delete',
  });
}

/**
 * 通过id 获取数据渲染 弹框
 */
export function EditWhiteIdGetData(id: any) {
  return request({
    url: `visitWhite/queryById/${id}`,
    method: 'get',
  });
}

/**
 * 新增 的确认  post data
 */
export function AddWhite(data: any) {
  return request({
    url: '/visitWhite/add',
    method: 'post',
    data,
  });
}

/**
 * 编辑 的确认
 */
export function EditWhiteIp(data: any) {
  return request({
    url: '/visitWhite/edit',
    method: 'put',
    data,
  });
}

/**
 * 导入
 */
export function ImportWhite(data: any) {
  return request({
    url: '/visitWhite/import',
    method: 'post',
    data,
  });
}

/**
 * 导出
 */
export const ExportWhite = (ids: any) => {
  return request({
    url: `/visitWhite/export?ids=${ids}`,
    method: 'post',
    responseType: 'blob',
  });
};

/**
 * 下载模版
 */
export const downloadTemplate = () => {
  return request({
    url: 'visitBlack/downloadTemplate',
    method: 'post',
    responseType: 'blob',
  });
};
